﻿<Window x:Class="StEditor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="600" Width="800" Loaded="Window_Loaded">
    <Grid>
        <Grid.Resources>
            <Style x:Key="TileStyle">
                <Setter Property="Canvas.Left" Value="{Binding X}" />
                <Setter Property="Canvas.Top" Value="{Binding Y}" />
            </Style>
            <ControlTemplate x:Key="ImageButton" TargetType="{x:Type Button}">
                <Canvas  Width="{Binding Width}" Height="{Binding Height}">
                    <Image Name="Img" Source="{Binding Image}" Width="{Binding Width}" Height="{Binding Height}" />
                    <Rectangle Name="Rect" Width="{Binding Width}" Height="{Binding Height}" Stroke="Red" Visibility="Hidden" />
                </Canvas>
                <ControlTemplate.Triggers>
                    <Trigger Property="Button.IsMouseOver" Value="True">
                        <Setter TargetName="Rect" Property="Visibility" Value="Visible" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            <ControlTemplate x:Key="TileButton" TargetType="{x:Type Button}">
                <Canvas  Width="32" Height="32">
                    <Image Name="Img" Source="{Binding}" Width="32" Height="32" Stretch="Uniform" />
                    <Rectangle Name="Rect" Width="32" Height="32" Stroke="Red" Visibility="Hidden" />
                </Canvas>
            </ControlTemplate>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="5*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="9*" />
        </Grid.RowDefinitions>

        <ToolBarTray Grid.Row="0" Grid.ColumnSpan="2">
            <ToolBar Band="1" BandIndex="1">
                <Button Name="Save" Content="Save" Click="Save_Click" />
                <Separator />
                <Button Name="Load" Content="Load" Click="Load_Click" />
                <Separator />
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Area: " Margin="3" />
                    <ComboBox Name="Areas" ItemsSource="{Binding GameAreas}" SelectedValue="{Binding CurrentArea}" Width="150" SelectedIndex="0" SelectionChanged="Areas_SelectionChanged">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding AreaName}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </StackPanel>
                <Button Name="AddArea" Content="New area" Command="{Binding AddNewAreaCommand}" />
                <Separator />
                <Button Name="AddTile" Content="Add tile" Click="AddTile_Click" />
                <Separator />
                <ToggleButton Name="FillMode" Content="Fill" Click="FillMode_Click" IsChecked="{Binding FillMode}" />
            </ToolBar>
        </ToolBarTray>

        <ItemsControl Grid.Row="1" Grid.Column="0" Name="map" ItemsSource="{Binding Path=CurrentArea.Tiles}" ItemContainerStyle="{StaticResource TileStyle}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas Width="600" Height="400" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Command="{Binding ClickedCommand}" Template="{StaticResource ImageButton}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical">
            <ListView ItemsSource="{Binding TileTypes}" Height="400">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Button Click="Button_Click" Template="{StaticResource TileButton}" />
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
            <TextBlock Text="Selected tile" />
            <Image Source="{Binding TileTypes.SelectedTile}" Width="{Binding CurrentArea.TileWidth}" Height="{Binding CurrentArea.TileHeight}" Stretch="None" MinHeight="32" MinWidth="32" />
            <CheckBox Content="Blocking" IsChecked="{Binding TileTypes.SelectedTile.Blocking}" />
        </StackPanel>
        <PasswordBox Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="244,207,0,0" Name="passwordBox1" VerticalAlignment="Top" Width="120" />
    </Grid>
</Window>
